/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pos.system.database;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import pos.system.OrderItem;

/**
 *
 * @author Shameera
 */
public class OrderDataTable extends AbstractTableModel{

        List<String[]> order = new ArrayList<String[]>();
    String[] columnNames = new String[]{"CODE", "NAME", "UNIT PRICE", "QTY" , "TOTAL"};

    public OrderDataTable() {
    }
    
    public void addItem(OrderItem item){
        order.add(new String []{item.getCode() ,item.getName() 
                , item.getPriceAsMoneyString() , String.valueOf(item.getAmount()) ,item.getTotalPriceAsMoneyString() });
        fireTableRowsInserted(order.size(), order.size());
    }
    
    @Override
    public int getRowCount() {
        return order.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return order.get(rowIndex)[columnIndex];
    }

    @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }
    
    public void clear(){
        int size = order.size();
        order.clear();
        fireTableRowsDeleted(0, size);
    }
    
    public void removeItem(int row){
        order.remove(row);
        fireTableRowsDeleted(row, row);
    }
}